<?php

namespace App\EventListener;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;

class ExceptionListener
{
    /**
     * @param ExceptionEvent $event
     *
     * @throws
     */
    public function onKernelException(ExceptionEvent $event)
    {
        $responseMessage = json_encode(
            ['code' => 0, 'message' => $event->getException()->getMessage()],
            JSON_UNESCAPED_UNICODE
        );
        $response        = new JsonResponse();
        $response->setContent($responseMessage);
        $event->setResponse($response);
    }
}
